package String;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class _401_BinaryWatch {
    List<String> results = new ArrayList<>();
    int[] hours = {8, 4, 2, 1};
    int[] minutes = {32, 16, 8, 4, 2, 1};
    public List<String> readBinaryWatch(int num) {
        getSubWatch(0, 0, 0, 0, num);
        return results;
    }

    //hint:treat hours and minutes as a big array:[hours][minutes],and pos circle from the pos to the end,
    //then get the hour and minute and judge if it's legal.
    //hint 2:the every bit in hours and minutes is unique,and any one of their sums is unique too.
    public void getSubWatch(int hour,int minute,int pos,int count, int max) {
        if (count == max) {
            if (hour < 12 && minute < 60) {
                String result = hour + ":";
                if (minute < 10) {
                    results.add(result + "0" + minute);
                } else {
                    results.add(result + minute);
                }
            }
        } else {
            for(int i=pos;i<hours.length+minutes.length;i++) {
                if (i < hours.length) {
                        getSubWatch(hour + hours[i], minute, i + 1, count + 1, max);
                } else {
                        getSubWatch(hour, minute + minutes[i - hours.length], i + 1, count + 1, max);
                }
            }
        }
    }

    @Test
    public void test() {
        String[] str1= {"11:48","11:40","11:36","11:34","11:33","11:24","11:20","11:18","11:17","11:12","11:10","11:09","11:06","11:05","11:03","10:56","10:52","10:50","10:49","10:44","10:42","10:41","10:38","10:37","10:35","10:28","10:26","10:25","10:22","10:21","10:19","10:14","10:13","10:11","10:07","9:56","9:52","9:50","9:49","9:44","9:42","9:41","9:38","9:37","9:35","9:28","9:26","9:25","9:22","9:21","9:19","9:14","9:13","9:11","9:07","8:58","8:57","8:54","8:53","8:51","8:46","8:45","8:43","8:39","8:30","8:29","8:27","8:23","8:15","7:48","7:40","7:36","7:34","7:33","7:24","7:20","7:18","7:17","7:12","7:10","7:09","7:06","7:05","7:03","6:56","6:52","6:50","6:49","6:44","6:42","6:41","6:38","6:37","6:35","6:28","6:26","6:25","6:22","6:21","6:19","6:14","6:13","6:11","6:07","5:56","5:52","5:50","5:49","5:44","5:42","5:41","5:38","5:37","5:35","5:28","5:26","5:25","5:22","5:21","5:19","5:14","5:13","5:11","5:07","4:58","4:57","4:54","4:53","4:51","4:46","4:45","4:43","4:39","4:30","4:29","4:27","4:23","4:15","3:56","3:52","3:50","3:49","3:44","3:42","3:41","3:38","3:37","3:35","3:28","3:26","3:25","3:22","3:21","3:19","3:14","3:13","3:11","3:07","2:58","2:57","2:54","2:53","2:51","2:46","2:45","2:43","2:39","2:30","2:29","2:27","2:23","2:15","1:58","1:57","1:54","1:53","1:51","1:46","1:45","1:43","1:39","1:30","1:29","1:27","1:23","1:15","0:55","0:47","0:31"};
        String[] str2 = {"0:31","0:47","0:55","0:59","1:15","1:23","1:27","1:29","1:30","1:39","1:43","1:45","1:46","1:51","1:53","1:54","1:57","1:58","2:15","2:23","2:27","2:29","2:30","2:39","2:43","2:45","2:46","2:51","2:53","2:54","2:57","2:58","3:07","3:11","3:13","3:14","3:19","3:21","3:22","3:25","3:26","3:28","3:35","3:37","3:38","3:41","3:42","3:44","3:49","3:50","3:52","3:56","4:15","4:23","4:27","4:29","4:30","4:39","4:43","4:45","4:46","4:51","4:53","4:54","4:57","4:58","5:07","5:11","5:13","5:14","5:19","5:21","5:22","5:25","5:26","5:28","5:35","5:37","5:38","5:41","5:42","5:44","5:49","5:50","5:52","5:56","6:07","6:11","6:13","6:14","6:19","6:21","6:22","6:25","6:26","6:28","6:35","6:37","6:38","6:41","6:42","6:44","6:49","6:50","6:52","6:56","7:03","7:05","7:06","7:09","7:10","7:12","7:17","7:18","7:20","7:24","7:33","7:34","7:36","7:40","7:48","8:15","8:23","8:27","8:29","8:30","8:39","8:43","8:45","8:46","8:51","8:53","8:54","8:57","8:58","9:07","9:11","9:13","9:14","9:19","9:21","9:22","9:25","9:26","9:28","9:35","9:37","9:38","9:41","9:42","9:44","9:49","9:50","9:52","9:56","10:07","10:11","10:13","10:14","10:19","10:21","10:22","10:25","10:26","10:28","10:35","10:37","10:38","10:41","10:42","10:44","10:49","10:50","10:52","10:56","11:03","11:05","11:06","11:09","11:10","11:12","11:17","11:18","11:20","11:24","11:33","11:34","11:36","11:40","11:48"};
        List<String> li1 = Arrays.asList(str1);
        List<String> li2 = Arrays.asList(str2);
        for(int i=0;i<str1.length;i++) {
            if (!li2.contains(str1[i])) {
                System.out.println(str1[i]);
            }
        }
        for(int i=0;i<str2.length;i++) {
            if (!li1.contains(str2[i])) {
                System.out.println(str2[i]);
            }
        }
    }

}
